package com.power.sifa.approve.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.sifa.approve.model.Apl_attachment;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 申请材料附件 持久层(hibernate)
 */

public interface Apl_attachmentDao extends JpaRepository<Apl_attachment, Serializable>, JpaSpecificationExecutor<Apl_attachment>, Repository<Apl_attachment, Serializable>, Apl_attachmentDaoCustom<Apl_attachment, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Apl_attachment s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);

    @Query(value = "from Apl_attachment where applyid = :applyid order by createtime")
    List<Apl_attachment> queryList(String applyid);

    @Query(value = "select a.*, b.name as material_name, b.stdattachid, b.ismanual from Apl_attachment a join Apl_matter_attach b on a.matter_attachid = b.id where a.applyid = :applyid and b.deleted = 0 order by b.sortnum", nativeQuery = true)
    List<Map> getListByApplyid(String applyid);

    @Query(value = "select matter_attachid from Apl_attachment where applyid = :applyid group by matter_attachid", nativeQuery = true)
    List<String> getMatterAttachid(String applyid);

}
